<template>
  <div class="examdetail">
    <div class="header">
      <h2>考试试卷</h2>
    </div>
    <div class="center">
      <!-- 表格 -->
      <el-table :data="content" border style="width: 90%; margin: 0 auto">
        <el-table-column prop="examId" label="试卷号" width="600">
        </el-table-column>
        <el-table-column prop="examName" label="姓名" width="600">
        </el-table-column>
        <el-table-column label="操作" width="500">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="primary"
              >开始考试</el-button
            >
            <!-- <el-button
              @click="handleClick2(scope.row)"
              type="primary"
              >错题解析</el-button
            > -->
            <el-button @click="handleClick1(scope.row)" type="primary"
              >查看排行榜</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "ExamDetail",
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      content: [], //试卷数组
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      total: 0, //数据的总共数目
      answerTime: "",
      examId: "",
      examId1: "", //考完试的试卷id
    };
  },
  created() {
    this.getdetail();
    this.getDisabled();
  },
  methods: {
    // 获取试卷
    getdetail() {
      var params = {
        currentPage: this.currentPage,
        pageSize: this.pageSize,
      };
      //   请求数据
      this.$http.get("/student/getExamList", { params }).then((res) => {
        if (res.code == 200) {
          this.$message.success(res.msg);
          this.content = res.data.content;
          this.total = res.data.total;
        }
      });
    },

    // 按钮
    handleClick(row) {
      this.examId = row.examId;
      this.$router.push({ name: "Home", query: { examId: row.examId } });
    },

    handleClick1(row) {
      this.$router.push({ name: "Score", query: { examId: row.examId } });
    },

    // handleClick2(row) {
    //   this.$router.push({ name: "Home", query: { examId: row.examId1 } });
    // },

    // 上一页
    handleSizeChange(newSize) {
      this.pageSize = newSize;
      this.getGradeList();
    },

    // 下一页
    handleCurrentChange(newPage) {
      this.currentPage = newPage;
      this.getGradeList();
    },

    // 判断按钮的状态
    // getDisabled() {
    //   this.examId1 = localStorage.getItem("examId");
    //   console.log(this.examId1);
    // },
  },
};
</script>